package com.woniu.bank.service.impl;

import com.woniu.bank.dto.DspDTO;
import com.woniu.bank.entity.AuditForm;
import com.woniu.bank.mapper.AuditFormMapper;
import com.woniu.bank.service.DspService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author ：lgy
 * @description：TODO
 * @date ：2023/1/5 17:32
 */
@Service
public class DspServiceImpl implements DspService {
    @Autowired
    private AuditFormMapper auditFormMapper;

    /**
     * lgy
     * 审批人审批贷款
     * @param dspDTO
     * @return
     */
    @Override
    public int updateDsp(DspDTO dspDTO) {
        AuditForm auditForm = auditFormMapper.selectByPrimaryKey((long) dspDTO.getApprovalStatusId());
        auditForm.setApprovalIme(new Date());
        auditForm.setApprovals(dspDTO.getApprovals());
        auditForm.setApprovalConclusions(dspDTO.getApprovalConclusions());
        auditForm.setApprovalOpinions(dspDTO.getApprovalOpinions());
        auditForm.setApprover(dspDTO.getApprover());
        if(auditForm.getApprovalStatus().equals("待审批")){
            if(dspDTO.getApprovalConclusions().equals("同意")){
                auditForm.setApprovalStatus("审批通过");
            }else if(dspDTO.getApprovalConclusions().equals("不同意")){
                auditForm.setApprovalStatus("审批不通过");
            }
        }
        return auditFormMapper.updateByPrimaryKeySelective(auditForm);
    }
}
